class: center, middle, inverse, title-slide # Getting map data into R --- layout: true <div class="dk-footer"> <span> <a href="https://rfortherestofus.com/" target="_blank">R for the Rest of Us </a> </span> </div> --- class: center, middle, dk-section-title background-image:url("images/sf-logo.gif") background-size: 400px # {sf} for simple features ??? --- ## Most maps contain simple features .pull-left[ This map shows the **5 busiest passenger routes** in 2015<br>(by total seat kilometres). It contains three types of feature: - LINESTRING for the flight routes - POINT for the airport location - POLYGON for the country borders ] .pull-right[
] ??? --- ## {sf} implements simple features for R - Simple features is a formal standard for organising and processing GIS data. -- - The `{sf}` package fully implements the simple features standards in R -- - The `{sf}` package ultimately provides us with a `data.frame()` like object that we can manipulate with the tidyverse. ``` ## Simple feature collection with 177 features and 2 fields ## Geometry type: MULTIPOLYGON ## Dimension: XY ## Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 83.64513 ## CRS: +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 ## # A tibble: 177 × 3 ## name continent geometry ## <chr> <chr> <MULTIPOLYGON [°]> ## 1 Afghanistan Asia (((61.21082 35.65007, 62.2306… ## 2 Angola Africa (((16.32653 -5.87747, 16.5731… ## 3 Albania Europe (((20.59025 41.8554, 20.46318… ## 4 United Arab Emirates Asia (((51.57952 24.2455, 51.75744… ## 5 Argentina South America (((-65.5 -55.2, -66.45 -55.25… ## 6 Armenia Asia (((43.58275 41.09214, 44.9724… ## 7 Antarctica Antarctica (((-59.57209 -80.04018, -59.8… ## 8 Fr. S. Antarctic Lands Seven seas (open ocean) (((68.935 -48.625, 69.58 -48.… ## 9 Australia Oceania (((145.398 -40.79255, 146.364… ## 10 Austria Europe (((16.97967 48.1235, 16.90375… ## # … with 167 more rows ``` ??? --- ## What can't {sf} do .pull-left[ The simple features standard does not include raster datasets. This might include: - air pollution data - meteorological data - satellite imagery ] .pull-right[
] ??? --- ## What can't {sf} do .pull-left[ You'll likely know up front if you're going to work with raster GIS datasets. We're going to focus on getting vector GIS datasets into R with `{sf}` before introducing `{raster}` and `{stars}` for raster datasets. ] .pull-right[
] ??? --- ## (RStudio Coding Slide) ??? --- ## {sf} replaces {sp} .pull-left[ `{sf}` is still a fairly new package, first appearing in 2016. It is designed to completely replace the older `{sp}` package. Thankfully, it's very easy to convert `{sp}` objecs to `{sf}`. ] -- .pull-right[ `{sp}` is responsible for the Spatial*DataFrame data sructure, eg: - SpatialPolygonsDataFrame - SpatialPointsDataFrame ] ??? --- ## Working with {sp} blogposts/tutorials .pull-left[ You have a two choices: - Use the existing `{sp}` code and convert the final output to an `{sf}` object. ] .pull-right[ <img src='images/sp-example-question.png' width="100%"> ] ??? --- ## Working with {sp} blogposts/tutorials .pull-left[ You have a two choices: - Use the existing `{sp}` code and convert the final output to an `{sf}` object. - Re-write the code to use `{sf}` throughout. **If you figure it out add a solution or write a blogpost!** ] .pull-right[ <img src='images/sp-example-question.png' width="100%"> ] ??? --- ## (RStudio Coding Slide) ??? --- class: inverse ### Your turn Use `mapview()` to visualise only the regions in `tiny_countries110` where the UN region is either "Seven Seas (open ocean)" or "Oceania". - Load the {tidyverse}, {mapview}, {rnaturalearthdata} and {sf} packages - Convert `tiny_countries110` into an sf object - Filter only those countries in "Seven Seas (open ocean)" or "Oceania" - Visualise this object with {mapview}